#include "Stress_Base.h"

void Stress_Base::SetStress(Eigen::MatrixXd& in, int n_coord, std::vector<double>& coord_c)
{
	m_coord.resize(n_coord);
	m_pStress.resize(in.cols() - 2 - n_coord);
	m_id = in(0, 0);
	weight = in(0, 1);
	for (int i = 0; i < n_coord; i++)
	{
		m_coord[i] = in(0, i + 2);
	}
	for (int i = 0; i < m_pStress.size(); i++)
	{
		m_pStress[i] = in(0, i + 2 + n_coord);
	}
}

void Stress_Base::foutStress(std::ofstream& fout)
{
	fout << std::left << std::setw(7) << m_id;
	for (int i = 0; i < m_coord.size(); i++)
	{
		fout << std::left << std::setw(20) << m_coord[i];
	}
	for (int i = 0; i < m_pStress.size(); i++)
	{
		fout << std::left << std::setw(20) << m_pStress[i];
	}
	fout << std::left << std::setw(20) << (m_pStress[0] + m_pStress[2]);
	fout << std::left << std::setw(20) << (m_pStress[1] + m_pStress[3]);
	fout << std::endl;
}

void Stress_Base::smoothout(std::vector<double>& stress)
{
	for (int i = 0; i < m_pStress.size(); i++)
	{
		stress[i] += weight * m_pStress[i];
	}
}

void Stress_Base::getweight(double& A)
{
	A += weight;
}
